/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.nostra13.sample.slice;

import com.nostra13.sample.ResourceTable;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.utils.L;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;

import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.window.dialog.ToastDialog;

public class MainAbilitySlice extends AbilitySlice {

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(com.nostra13.sample.ResourceTable.Layout_ability_main);

        findComponentById(ResourceTable.Id_listView).setClickedListener(v -> {
            startActivity("com.nostra13.sample.ListViewAbility");
        });
        findComponentById(ResourceTable.Id_gridView).setClickedListener(v -> {
            startActivity("com.nostra13.sample.GridViewAbility");
        });
        findComponentById(ResourceTable.Id_viewPager).setClickedListener(v -> {
            startActivity("com.nostra13.sample.ViewPagerAbility");
        });
        findComponentById(ResourceTable.Id_gallery).setClickedListener(v -> {
            startActivity("com.nostra13.sample.GalleryAbility");
        });
        findComponentById(ResourceTable.Id_imagePicker).setClickedListener(v -> {
            startActivity("com.nostra13.sample.ImageAbility");
        });
    }


    private void startActivity(String abilityName) {
        Intent secondIntent = new Intent();
        Operation operation = new Intent.OperationBuilder()
                .withDeviceId("")
                .withBundleName("com.nostra13.sample")
                .withAbilityName(abilityName)
                .build();
        secondIntent.setOperation(operation);
        startAbility(secondIntent);
    }

    @Override
    public void onActive() {
        super.onActive();
        ImageLoader.getInstance().clearMemoryCache();
        ImageLoader.getInstance().clearDiskCache();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
